package cn.edu.stu.syllabus.library.query;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import cn.edu.stu.syllabus.R;
import cn.edu.stu.syllabus.base.BaseActivity;
import cn.edu.stu.syllabus.library.detail.BookDetailActivity;
import cn.edu.stu.syllabus.library.star.BookStarActivity;
import cn.edu.stu.syllabus.utils.ActivityUtils;
import cn.edu.stu.syllabus.utils.GuideHelper;

public class QueryBooksActivity extends BaseActivity implements Toolbar.OnMenuItemClickListener {


    @Override
    protected int getContentViewId() {
        return R.layout.activity_query_books;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setTitle("图书检索");

        mToolbar.inflateMenu(R.menu.menu_query_library);
        mToolbar.setOnMenuItemClickListener(this);

        QueryBooksFragment queryBooksFragment = (QueryBooksFragment) getSupportFragmentManager()
                .findFragmentById(R.id.contentFrame);
        if (queryBooksFragment == null) {
            queryBooksFragment = QueryBooksFragment.newInstance();
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(),
                    queryBooksFragment, R.id.contentFrame);
        }

        GuideHelper.startActSeqNow(this,
                GuideHelper.getActMainTapTarget(R.drawable.ic_library, this,
                        "这是图书检索主界面",
                        "可以输入关键字等信息获取对应的书籍信息")
                        .id(1),
                GuideHelper.getToolbarItemTapTarget(mToolbar, R.id.action_fav_book,
                        "这是打开收藏夹的按钮",
                        "点击后, 你可以查看加入收藏夹的手机信息")
                        .id(2)
        );


    }

    @Override
    public boolean onMenuItemClick(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_fav_book) {
            Intent intent = BookStarActivity.newIntent(this);
            startActivity(intent);
        }

        return true;
    }
}
